package com.fasteat.util;


import java.util.*;

/**
 * 用于记录已上线的客服
 */
public class ServiceRecord {
    private static List<String> serviceIdList = new ArrayList<>();//记录已上线的客服id
    private static HashSet<String> serviceIdSet = new HashSet<>();//用于快速判断是否为客服
    private static int index = 0; //轮询记录下标

    public static void add(String serviceId){
        serviceIdList.add(serviceId);
        serviceIdSet.add(serviceId);
    }

    //轮询获取客服id
    //无客服在线时将抛出异常
    public static String get() throws IndexOutOfBoundsException{
        String serviceId = serviceIdList.get(index);
        if(index + 1 < serviceIdList.size()){
            index++;
        }else index = 0;
        return serviceId;
    }

    public static boolean remove(String serviceId){
        serviceIdSet.remove(serviceId);
        return serviceIdList.remove(serviceId);
    }

    public static boolean isService(String removedUserId){
        return serviceIdSet.contains(removedUserId);
    }
}
